<!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>{$Think.config.site.title} - 修改密码</title>
    <meta name="keywords" content="{$Think.config.site.keywords}">
    <meta name="description" content="{$Think.config.site.description}">

    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">

</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
      <div class="row">
          <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>修改密码 <small>修改密码后会重新登录</small></h5>
         
                    </div>
                    <div class="ibox-content">
                        <form method="post" class="form-horizontal">
                            
       
                            <div class="form-group">
                                <label class="col-sm-2 control-label">原密码</label>

                                <div class="col-sm-10">
                                    <input type="password" class="form-control" name="oldpassword" id="oldpassword">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">新密码</label>

                                <div class="col-sm-10">
                                    <input type="password" class="form-control" name="password" id="password">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">确认新密码</label>

                                <div class="col-sm-10">
                                    <input type="password" class="form-control" name="surepassword" id="surepassword">
                                </div>
                            </div>
                            <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary" type="submit">确认更改</button>
                           
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/validate/jquery.validate.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
  <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
</body>

</html>
<script>
$(document).ready(function(){
	$("form").validate({
	  debug:true,
	  submitHandler:function(form){
            post();   
      },    
	  rules: {
		oldpassword: {
		  required: true,
		  minlength: 6,
		},
		password: {
		  required: true,
		  minlength: 6,
		},
		surepassword : {
		  required: true,
		  equalTo: "#password"
		}
	  },
	  messages: {
		oldpassword: {
		  required: '原密码必须填写',
		  minlength: '原密码不能少于4位',
		},
		password: {
		  required: '密码必须填写',
		  minlength: '密码不能少于6位',
		},
		surepassword : {
		  required: '密码必须填写',
		  equalTo: "两次密码不同"
		}
	  }
	});
	function post(){
		var oldpassword = $("#oldpassword").val();
		var password = $("#password").val();
		var surepassword = $("#surepassword").val();
		$.ajax({
			type : 'POST',
			url : '<?php echo \think\Request::instance()->root(); ?>/admin/Password',
			dataType : 'json',
			data : {oldpassword : oldpassword, password : password},
			success : function(result) {
				//layer.close(layer1);
				if(0 === result.code) {
					layer.msg('修改成功，即将跳转到登录界面！', {icon: 1});
					setTimeout(function(){
						top.location.href = '<?php echo \think\Request::instance()->root(); ?>/admin/Login';
					},1500);
				}  else  {
					//修改失败
					layer.msg(result.msg, {icon: 5});
				}
			},
			error : function(){
		
				layer.msg('服务器错误！请稍后重试', {icon: 2});
			}
		})
	};
})
</script>